<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Support\Facades\Cookie;

class AdminLogin
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        $user_data = $request->cookie('adminlogin');

        if (!empty($user_data)) 
        {
            $user_data = unserialize($user_data);
            if ($user_data['token'] == md5($user_data['id'].$user_data['phone'])) 
            {
                return $next($request);
            }
        }
        return redirect('/Xlogin');
    }
}
